package com.tubi.servlet;

import javax.servlet.ServletContainerInitializer;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRegistration;
import java.util.Set;

/*
*
* 注册配置servlet的功能类
*
* */

public class MyRegister implements ServletContainerInitializer {
    @Override
    public void onStartup(Set<Class<?>> set, ServletContext servletContext) throws ServletException {
        // 完成wervlet的创建配置
        //1.创建servletDemo2 的对象
        ServletDemo2 servletDemo2 = new ServletDemo2();
        //2.在servletContext 对象中添加Servlet 并得到Servlet的动态配置
        ServletRegistration.Dynamic registration = servletContext.addServlet("servletDemo02", servletDemo2);
        //配置Servlet
        registration.addMapping("/servletDemo02");//映射访问资源的路径
        registration.setLoadOnStartup(1);//Servlet 加载时机
    }
}
